/*
 * Copyright (c) 2011 Jean-Marc Perronne
 * Ensisa, 12 rue des Freres Lumieres, F-68093 Mulhouse cedex
 * All rights reserved.
 *
 * The copyright of this software is owned by Werner Randelshofer. 
 * You may not use, copy or modify this software, except in  
 * accordance with the license agreement you entered into with  
 * Jean-Marc Perronne. For details see accompanying license terms. 
 */

package fr.uha.ensisa.jmp.ui.model;

import java.util.Collection;
import java.util.Map;
import java.util.TreeMap;

import javax.swing.event.ChangeListener;

public class DefaultCompoundModel implements CompoundBoundedModel
{
	protected Map<String, BoundedModel> models;
	
	public DefaultCompoundModel()
	{
		this.models = new TreeMap<String, BoundedModel>();
	}
	
	@Override
	public void addModel(String key, BoundedModel model)
	{
		this.models.put(key, model);
	}

	@Override
	public void removeModel(String key)
	{
		this.models.remove(key);
	}

	@Override
	public int getMaximum(String modelKey)
	{
		return this.models.get(modelKey).getMaximum();
	}

	@Override
	public int getMinimum(String modelKey)
	{
		return this.models.get(modelKey).getMinimum();
	}

	@Override
	public int getValue(String modelKey)
	{
		return this.models.get(modelKey).getValue();

	}

	@Override
	public void setMaximum(String modelKey, int v)
	{
		this.models.get(modelKey).setMaximum(v);
	}

	@Override
	public void setMinimum(String modelKey, int v)
	{
		this.models.get(modelKey).setMinimum(v);
	}

	@Override
	public void setValue(String modelKey, int v)
	{
		this.models.get(modelKey).setValue(v);
	}

	public void addChangeListener(String modelKey, ChangeListener l)
	{
		this.models.get(modelKey).addChangeListener(l);
	}
	
	public void removeChangeListener(String modelKey, ChangeListener l)
	{
		this.models.get(modelKey).removeChangeListener(l);
	}

	@Override
	public Collection<BoundedModel> models()
	{
		return this.models.values();
	}

}
